import pandas as pd
import glob, folium, branca, json
import numpy as np
import matplotlib.pyplot as plt
print(np.datetime64('now'))
2021-02-16T00:28:17
# PUT EVERY COUNTRY REPORTS IN ONE DATAFRAME
files = glob.glob('data/install*country.csv')
files.sort()
ds=pd.DataFrame()
for f in files:
ds = pd.concat([ds,pd.read_csv(f,encoding = 'utf-16')])
ds.tail()
| Date | Package Name | Country | Daily Device Installs | Daily Device Uninstalls | Daily Device Upgrades | Total User Installs | Daily User Installs | Daily User Uninstalls | Active Device Installs | Install events | Update events | Uninstall events | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 224 | 2021-02-12 | com.kb.android.argo | MY | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 |
| 225 | 2021-02-12 | com.kb.android.argo | NO | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 |
| 226 | 2021-02-12 | com.kb.android.argo | RU | 1 | 0 | 0 | 0 | 1 | 0 | 2 | 1 | 0 | 0 |
| 227 | 2021-02-12 | com.kb.android.argo | SI | 0 | 0 | 0 | 0 | 0 | 0 | 2 | 0 | 0 | 0 |
| 228 | 2021-02-12 | com.kb.android.argo | US | 0 | 0 | 0 | 0 | 0 | 0 | 5 | 0 | 0 | 0 |
with plt.style.context('seaborn'):
fig,ax = plt.subplots(1,figsize=(20,10))
ax.plot(ds['Date'],ds['Daily Device Installs'].cumsum(),'#ff6f69',linewidth=3)
ax.plot(ds['Date'],ds['Daily User Installs'].cumsum(),'#88d8b0',linewidth=3)
tk = ax.get_xticks()
plt.xticks(np.linspace(min(tk), max(tk), 10))
plt.xticks(rotation=45)
plt.ylabel('installations')
devicecount = ds['Daily Device Installs'].cumsum().values[-1]
usercount = ds['Daily User Installs'].cumsum().values[-1]
a = plt.text(ds['Date'].values[0],devicecount/1.3,str(devicecount)+' devices',fontsize=25,color='#ff6f69')
b = plt.text(ds['Date'].values[0],devicecount/1.6,str(usercount)+' users',fontsize=25,color='#88d8b0')
c = plt.text(ds['Date'].values[0],devicecount/2.,str(len(np.unique(ds['Country'][~ds['Country'].isna()])))+' countries',fontsize=25,color='#ffcc5c')
ax.grid(True, linewidth=1, linestyle='-.')
#plt.savefig('installations.png',dpi=200)
df = pd.DataFrame(ds.groupby('Country').sum()['Daily User Installs'])
color_scale = branca.colormap.linear.viridis.scale(0,20)
map_dict = df.to_dict()
def get_color(feature):
value = map_dict['Daily User Installs'].get(feature['properties']['ISO_A2'])
if value is None:
return 'white' # MISSING -> white
else:
print(feature['properties']['ADMIN']+' : '+str(value))
return color_scale(value)
m = folium.Map(
location = [0, 0],
tiles="cartodbpositron",
zoom_start = 2
)
folium.GeoJson(
data = 'countries.json',
style_function = lambda feature: {
'fillColor': get_color(feature),
'fillOpacity': 0.7,
'color' : 'None',
'weight' : 1,
}
).add_to(m)
m.add_child(color_scale)
#m.save('map.html')
m
Australia : 3 Belgium : 1 Brazil : 1 Canada : 1 Switzerland : 1 Chile : 3 Colombia : 1 Germany : 2 Denmark : 1 Spain : 12 Finland : 1 Fiji : 1 France : 16 United Kingdom : 5 Croatia : 0 Indonesia : 1 India : 2 Japan : 4 Kazakhstan : 1 Mexico : 1 Myanmar : 1 Malaysia : 1 Norway : 2 Pakistan : 2 Russia : 5 El Salvador : 1 Slovenia : 1 United States of America : 5